
package system.communication;

import system.ui.Engine;

/**
 * The HandControlMessageNotifier is used to poll the Monitor for recent HandControl
 * Message types. It pulls the messages from the Monitor and pushes them onto the
 * HandController.
 *
 * @author elliot
 */
public class HandControlMessageNotifier extends Thread
{
    private HandController hc1;
    private HandController hc2;

    /**
     * Default HandControlMessageNotifier constructor
     */
    public HandControlMessageNotifier()
    {

    }

    /**
     * Overloaded HandControlMessageNotifier constructor which sets internal references
     * to the HandController's
     *
     * @param hc1 HandController object with id of 1.
     * @param hc2 HandController object with id of 2.
     */
    public HandControlMessageNotifier(HandController hc1, HandController hc2)
    {
        this();
        this.hc1 = hc1;
        this.hc2 = hc2;
    }

    /**
     * Overrided run method for Thread implementation, which checks Monitor for
     * HandControl Messages and updates the status of the HandControllers. Also notifies
     * the MessageListener of it's death.
     */
    @Override
    public void run()
    {
        while(!Monitor.handControlMessages.isEmpty())
        {
            Message theMessage = Monitor.handControlMessages.removeLast();
            Engine.getInstance().postMessage(
                    theMessage,
                    false);
            switch(theMessage.getId())
            {
                case 1:
                    hc1.updateStatus(theMessage);
                    break;
//                case 2:
//                    hc2.updateStatus(theMessage);
//                    break;
            }
        }
        Monitor.getInstance().getMessageListener()
                .handControllerMessageNotifierDeath();
    }

    /**
     * End method for Thread implementation.
     */
    public void end()
    {
        
    }

}
